package cn.tedu.web;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class GetCookieServlet
 */
public class GetCookieServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//从Request中读取浏览器传回的Cookie
		//如果没有任何Cookie返回值为 null
		//如果有Cookie返回一个数组,包含每个Cookie信息
		
		Cookie[] cookies=request.getCookies();
		if(cookies!=null) {
			for(Cookie cookie:cookies) {
				String name=cookie.getName();
				String value=cookie.getValue();
				//解码
				value=URLDecoder.decode(value, "utf-8");
				System.out.println(name+" : "+value);
			}
		}
		response.setContentType("text/heml;charset=utf-8");
		response.getWriter().println("苍老师");
	}

}
